import java.util.ArrayList;
import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;
    public MyStack(){
        this.elem = new int[5];
    }


    public void push(int val){
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize] = val;
        usedSize++;
    }
    private boolean isFull(){
        return this.usedSize == this.elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyException("栈为空");
        }
        int tmp = elem[usedSize-1];
        usedSize--;
        return tmp;
    }

    private boolean isEmpty(){
        return this.usedSize == 0;
    }

    public int peek(){
        if(isEmpty()){
            throw new EmptyException("栈为空");
        }
        int tmp = elem[usedSize-1];
        return tmp;
    }
}
